;*****************************************************
; 	Copyright (C) SEIKO EPSON CORP. 1997-2001
;	All rights Reserved
;
;	File name : strchr.s
;	Function  :
;	       This is strchr function
;	Revision  :
;		1997/03/25	V.Chan start
;		2001/12/06	T.Tazaki for GNU33(Linux)
;*****************************************************

;*****************************************************
; strchr
;		find first occurrence of char in src (0 terminated)
;
; arguments : %r6:src addr, %r7:char
; return    : %r4:located char addr
;*****************************************************

	.section .text
	.align 1
	.global strchr
	.type	strchr,@function

strchr:
	ld.w	%r4, 0
				
strchr_loop:
	ld.ub	%r10, [%r6]+	; load byte
	cmp		%r10, %r7
	jreq	afterloop
	cmp		%r10, 0			; exit after NULL
	jreq	strchr_ret
	jp		strchr_loop

afterloop:
	sub		%r6, 1		; move back 1 byte
	ld.w	%r4, %r6	; addr of char

strchr_ret:
	ret

